package com.egor.data.repository;

import com.egor.data.entity.Employee;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface EmployeeRepository extends JpaRepository<Employee, Long> {
    @Query("""
           select c from Employee c
           where lower(c.firstName) like lower(concat('%', :searchTerm, '%'))
           or lower(c.lastName) like lower(concat('%', :searchTerm, '%'))
           or lower(c.secondName) like lower(concat('%', :searchTerm, '%'))
           """)
    Page<Employee> search(@Param("searchTerm") String searchTerm, Pageable pageable);
}